<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>音乐搜索与播放</title>
    <style>
        :root {
            --bg-color: #f4f4f4;
            --primary-color: #007BFF;
            --hover-color: #0056b3;
            --text-color: #333;
            --column-width: 33%;
            --red-1: 255,236,232;
            --orange-1: 255,247,232;
            --blue-1: 232,247,255;
            --font-size: 16px;
            --line-height: 1.5;
        }
        li:hover {
            background-color: rgba(var(--red-1), 0.3);
        }
        .playing {
            background-color: rgba(var(--blue-1), 1);
        }
        body {
            font-family: 'Arial', sans-serif;
            background: var(--bg-color);
            margin: 0;
            padding: 10px;
            padding-bottom: 100px;
        }
        header {
            background-color: #fff;
            padding: 20px 40px;
            text-align: center;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        form {
            margin-top: 20px;
            text-align: center;
        }
        input[type="text"] {
            width: 300px;
            padding: 10px;
            margin-right: 10px;
            border: 2px solid #ccc;
            border-radius: 5px;
        }
        button {
            padding: 10px 20px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: var(--hover-color);
        }
        ul {
            list-style-type: none;
            padding: 0;
            margin: 20px 0;
        }
        li {
            background: var(--blue-1);
            color: var(--text-color);
            margin-bottom: 10px;
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            font-size: var(--font-size);
            line-height: var(--line-height);
            cursor: pointer;
        }
        .column {
            width: var(--column-width);
            text-align: center;
        }
        audio {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 60px;
            background: white;
            box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
        }
        #timeDisplay, #speedControl, #playMode, #volumeControl {
    margin: 0 10px;
}

#volumeControl {
    width: 100px;
}
#audioPlayerBar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: white;
    padding: 10px;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
}
    </style>
</head>
<body>
    <header>
        <h1>搜索音乐</h1>
    </header>
    <form id="searchForm">
        <input type="text" id="searchQuery" placeholder="输入艺术家、歌曲或专辑" required>
        <button type="submit">搜索</button>
    </form>
    <div id="results"></div>

    <div id="audioPlayerBar">
    <audio id="audioPlayer" controls style="display: none;">
        <source id="audioSource" type="audio/mpeg">
        您的浏览器不支持音频元素。
    </audio>
    <button id="prevButton">|<</button>
    <button id="playPauseButton">||</button>
    <button id="nextButton">>|</button>
    <div id="timeDisplay">00:00 / 00:00</div>
    <select id="speedControl">
        <option value="0.5">0.5x</option>
        <option value="1" selected>1x</option>
        <option value="1.5">1.5x</option>
        <option value="2">2x</option>
    </select>
    <select id="playMode">
        <option value="sequential">顺序</option>
        <option value="loop">循环</option>
        <option value="random">随机</option>
    </select>
    <input type="range" id="volumeControl" min="0" max="100" value="100">
</div>

    <script>
        document.getElementById('searchForm').addEventListener('submit', function(event) {
            event.preventDefault();
            const query = document.getElementById('searchQuery').value;
            fetch(`/search?query=${query}`)
                .then(response => response.text())
                .then(html => {
                    document.getElementById('results').innerHTML = html;
                })
                .catch(error => console.error('Error loading data:', error));
        });
        function playMusic(link, title, element) {
            const player = document.getElementById('audioPlayer');
            const source = document.getElementById('audioSource');
            source.src = link;
            player.load();
            player.play();
            document.title = title; // 更新标签页标题为歌曲名
            const currentlyPlaying = document.querySelector('.playing');
            if (currentlyPlaying) {
                currentlyPlaying.classList.remove('playing');
            }
            element.classList.add('playing');
        }

    </script>
</body>
</html>
